<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://blogs">

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		

	<xsl:template name="article-options" match="object[@type='article']">
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="allowVote" select="@vote-allow" />
		
		<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id))/data/response/vote" mode="post-vote" />
		
		<div class="post_time">
			<xsl:choose>
				<xsl:when test="property[@name='draft']/value = '1' and property[@name='published']/value = '0'">
					<xsl:text>&labelPostNotPub;</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="property[@name='pubdate']/value" />
				</xsl:otherwise>
			</xsl:choose>
		</div>
		
		<xsl:if test="@type = 'link'">
			<div class="link_uri">
				<a href="{$baseURI}/blogs/link/{@id}">
					<xsl:attribute name="title">
						<xsl:value-of select="concat (property[@name='link']/value, ' | &labelLinkGoes;: ', property[@name='clicks']/value)" />
					</xsl:attribute>
					<xsl:value-of select="php:functionString ('XSLTDotsString', property[@name='link']/value, 30)" />
				</a>
			</div>
		</xsl:if>
		
		<div class="u_link">
			<a href="{$baseURI}/user/{$userLogin}">
				<xsl:value-of select="property[@name='user_name']/value" />
			</a>
		</div>
		
		<div class="comments">
			<a title="&labelComments;" href="{$baseURI}/post/{@type}/{@id}#comments">
				<xsl:value-of select="property[@name='count_comments']/value" />
			</a>
		</div>
		
		<xsl:if test="@editable = '1'">
			<div class="post_controls">
				<a title="&labelEdit;" href="{$baseURI}/blogs/edit/{@type}/{@id}">
					<img src="{$baseURI}/images/settings-icon.png" align="top" alt="" />
				</a>
			</div>
		</xsl:if>
	</xsl:template>
	
	<!-- POST VOTE -->
	<xsl:template match="vote" mode="post-vote">
		<xsl:param name="postId" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="typeId" select="type_id" />
		<xsl:param name="rating" select="rating" />
		
		<div class="post_rating">
			<div>
				<a id="pots_vote_plus_{$typeId}_{$postId}" href="javascript:void(0);" title="&labelLike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '1'">
								<img src="{$baseURI}/images/post-voted-plus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '1'">
								<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('votePost (', $postId, ', ', $typeId, ', 1);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-plus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
			<div class="post_rating_number" id="post_rating_{$typeId}_{$postId}">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">post_rating_number plus</xsl:attribute>
					<xsl:text>+</xsl:text>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">post_rating_number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$rating" />
			</div>
			<div>
				<a id="pots_vote_minus_{$typeId}_{$postId}" href="javascript:void(0);" title="&labelDislike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '0'">
								<img src="{$baseURI}/images/post-voted-minus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '0'">
								<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('votePost (', $postId, ', ', $typeId, ', 0);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-minus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>